package com.lz.yz.member.web;

import com.lz.yz.base.entity.ReturnValue;
import com.lz.yz.empowerment.model.LableModel;
import com.lz.yz.member.model.MemberLableModel;
import com.lz.yz.member.service.UserLableService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
* Created by CodeGenerator on 2017/11/09.
*/
@RestController
@RequestMapping("/user/lable")
public class UserLableController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private UserLableService userLableService;

    @Autowired
    HttpServletRequest request;


    @ApiOperation(value="添加标签")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer "),
            @ApiImplicitParam(name = "memberLableModel", value = "标签实体类", dataType = "MemberLableModel", paramType = "body"),
    })
    @PostMapping
    public ReturnValue add(@RequestBody MemberLableModel memberLableModel) {
        Integer accountId= (Integer) request.getAttribute("accountId");
        memberLableModel.setAccountId(accountId);
        return   userLableService.addMemberLable(memberLableModel);

    }

    @ApiOperation(value="我的标签",response = LableModel.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer ")

    })
    @GetMapping("/memberLable")
    public ReturnValue queryLable() {
        try {
            Integer accountId = (Integer) request.getAttribute("accountId");
            return userLableService.queryMemberLable(accountId);
        }  catch (Exception e) {
            logger.error("获取我的标签异常", e);
            return ReturnValue.generateFalseReturnValue("获取我的标签异常!");
        }
    }



    @ApiOperation(value="删除标签")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "Authorization",value = "Bearer token",defaultValue = "Bearer "),
            @ApiImplicitParam(name = "memberLableModel", value = "标签实体类", dataType = "MemberLableModel", paramType = "body"),
    })
    @PostMapping("/deleteMemberLable")
    public ReturnValue delete(@RequestBody MemberLableModel memberLableModel) {
        Integer accountId= (Integer) request.getAttribute("accountId");
        memberLableModel.setAccountId(accountId);
        return   userLableService.deleteMemberLable(memberLableModel);

    }

}
